package com.ytwl.controller.sche;

import com.ytwl.bean.RespBean;
import com.ytwl.bean.RespPageBean;
import com.ytwl.bean.Truck;
import com.ytwl.service.ScheService;
import com.ytwl.service.TruckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/sche")
public class ScheController {
    @Autowired
    ScheService scheService;
    @Autowired
    TruckService truckService;

    @GetMapping("/")
    public RespPageBean getAllScheduling(Integer page, Integer size) {
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setTotal(scheService.getTotal());
        respPageBean.setData(scheService.getAllScheduling(page,size));
        return respPageBean;
    }

    @PostMapping("/")
    public RespBean sche(Integer carriersid, Integer truckid, String startTime) {
        if (scheService.updateSche(carriersid, truckid, startTime)) {
            return RespBean.ok("调度成功!");
        }
        return RespBean.error("调度失败!");
    }
    @GetMapping("/carriers")
    public RespPageBean getAllCarriers(Integer page, Integer size, @RequestParam(defaultValue = "0") Integer state) {
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setData(scheService.getAllCarriers(page,size,state));
        respPageBean.setTotal(scheService.getCarriersTotal(state));
        return respPageBean;
    }

    @GetMapping("/truck")
    public List<Truck> getAllTruckByState() {
        return truckService.getAllTruckByState(2);
    }
}
